﻿// ----------------------------------------------------------------------------------
// <copyright file="PluggableForAllValuesOfEnumAttribute.cs" company="Christopher Hines">
// Copyright (c) 2012 All Right Reserved
// </copyright>
// <author>Chris Hines</author>
// <date>2012-03-26</date>
// <summary>
//     An attribute decorating a class as pluggable for all values of a specific enum type
// </summary>
// ----------------------------------------------------------------------------------

namespace Copperfield
{
    using System;
    using System.Linq;

    /// <summary>
    /// An attribute decorating a class as pluggable for all values of a specific enum type
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
    public sealed class PluggableForAllValuesOfEnumAttribute : ContextFilterAttribute
    {
        /// <summary>
        /// The filter type.
        /// </summary>
        private readonly Type filterType;

        /// <summary>
        /// Initializes a new instance of the <see cref="PluggableForAllValuesOfEnumAttribute"/> class.
        /// </summary>
        /// <param name="filterType">
        /// The filter type.
        /// </param>
        public PluggableForAllValuesOfEnumAttribute(Type filterType)
            : base(filterType, Enum.GetValues(filterType).OfType<object>().ToArray(), false)
        {
            this.filterType = filterType;
   
            if (!filterType.IsEnum)
            {
                throw new ArgumentException("The filter type must be a type of Enum", "filterType");
            }
        }

        /// <summary>
        /// Gets the filter type.
        /// </summary>
        public Type FilterType
        {
            get
            {
                return this.filterType;
            }
        }
    }
}
